import requests
import re
import time

s = requests.Session()
# 返回一个可以维持状态的Session
# 相当于处于打开状态的cookie管理器


def doLogin(youraccount):
    login_url = 'http://www.renren.com/ajaxLogin/login?1=1&uniqueTimestamp=2018321648829'
    data = {
        'email': youraccount,
        'icode': '',
        'origURL': 'http://www.renren.com/home',
        'domain': 'renren.com',
        'key_id': '1',
        'captcha_type': 'web_login',
        'password': '478b7c2dca554eeabed3b7374703bff4a6a22e78b8a9fcfb090e3a7fb792992b',
        'rkey': 'e954ec64a7ecf4e33bdf81bb1abad158',
        'f': 'http%3A%2F%2Fwww.renren.com%2F965541786',
    }

    res = s.post(login_url, data=data)
    # requests可以把创建请求对象和提交数据返回一个返回对象,两步合成一步


def myHome():
    home_url = 'http://www.renren.com/965541786'
    res = s.get(home_url)
    html = res.content.decode("utf-8")
    # print(html)
    print(re.findall("<title>(.*?)</title>", html))


if __name__ == '__main__':
    # 登陆
    while True:
        youraccount = input('请输入你的账户：')
        if youraccount != '13632635022':
            print('账号或密码错误')
            break
        print("正在登录中...")
        doLogin(youraccount)
        time.sleep(1)

        # 访问个人首页
        myHome()
        break
